import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-08-17
 * Time: 8:39
 * To BE A Better Person-2020-3-2
 */
//newFixedThreadPool: 创建固定线程数的线程池
//newCachedThreadPool: 创建线程数目动态增长的线程池.
//newSingleThreadExecutor: 创建只包含单个线程的线程池.
//newScheduledThreadPool: 设定 延迟时间后执行命令，或者定期执行命令. 是进阶版的 Timer
public class TestDemo2 {
    public static void main(String[] args) {
        ExecutorService pool=Executors.newScheduledThreadPool(10);
        pool.submit(()->{
            for (int i = 0; i < 10; i++) {
                System.out.println("hello ttt");
            }
        });
    }

    public static void main3(String[] args) {
        ExecutorService pool=Executors.newSingleThreadExecutor();
        pool.submit(()->{
            for (int i = 0; i < 10; i++) {
                System.out.println("hello ttt");
            }
        });
    }

    public static void main2(String[] args) {
        ExecutorService pool=Executors.newCachedThreadPool();
        pool.submit(()->{
            for (int i = 0; i < 10; i++) {
                System.out.println("hello ttt");
            }
        });
    }

    public static void main1(String[] args) {
        //工厂方法（工厂模式），防止构造方法重载，必须和类名一样。（笛卡尔坐标，极坐标）；
        ExecutorService pool= Executors.newFixedThreadPool(10);
        pool.submit(()->{
           while(true){
               System.out.println("hello ttt");
           }
        });
    }
}
